<!--
 * @Author: zhangYaRan
 * @Date: 2020-06-01 10:00:55
 * @LastEditors: zhangYaRan
 * @LastEditTime: 2020-06-01 10:51:48
 * @Description:用户缴费账单
-->
<template>
  <div class="registered-container userPayBilling appMainWarp">
    <el-form :inline="true" :model="searchKey" class="demo-form-inline">
      <el-form-item label="医疗机构:">
        <el-input v-model="searchKey.medicalInstitution" placeholder="请输入搜索内容" />
      </el-form-item>

      <el-form-item label="账单日期:">
        <el-date-picker
          v-model="searchKey.time"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <el-form-item label="状态:">
        <el-select v-model="searchKey.status" placeholder="请选择" @change="onSearch">
          <el-option
            v-for="item in searchKey.statusList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="赔偿方式:">
        <el-select v-model="searchKey.compensationWay" placeholder="请选择" @change="onSearch">
          <el-option
            v-for="item in searchKey.statusList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="赔偿状态:">
        <el-select v-model="searchKey.compensationStatus" placeholder="请选择" @change="onSearch">
          <el-option
            v-for="item in searchKey.compensationStatusList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="账单流水号:">
        <el-input v-model="searchKey.payOrderNo" placeholder="请输入搜索内容" />
      </el-form-item>

      <el-form-item label="姓名:">
        <el-input v-model="searchKey.name" placeholder="请输入搜索内容" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="onSearch">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="success" icon="el-icon-download" @click="onSearch">导出</el-button>
      </el-form-item>
    </el-form>

    <template>
      <el-table
        ref="table"
        v-loading="page.tableLoading"
        center
        class="table"
        :data="searchDate"
        stripe
        border
      >
        <el-table-column label="账单流水号" align="center">
          <template slot-scope="scope">{{ scope.row.id ||'-' }}</template>
        </el-table-column>
        <el-table-column label="账单子流水号" align="center">
          <template slot-scope="scope">{{ scope.row.username ||'-' }}</template>
        </el-table-column>
        <el-table-column label="账单日期" align="center">
          <template slot-scope="scope">{{ scope.row.username ||'-' }}</template>
        </el-table-column>
        <el-table-column label="就诊日期" align="center">
          <template slot-scope="scope">{{ scope.row.status||'-' }}</template>
        </el-table-column>
        <el-table-column label="姓名" align="center">
          <template slot-scope="scope">{{ scope.row.login_time ||'-' }}</template>
        </el-table-column>
        <el-table-column label="挂号单号" align="center">
          <template slot-scope="scope">{{ scope.row.login_ip ||'-' }}</template>
        </el-table-column>
        <el-table-column label="医疗机构" align="center">
          <template slot-scope="scope">{{ scope.row.login_ip ||'-' }}</template>
        </el-table-column>
        <el-table-column label="账单应付费用" align="center">
          <template slot-scope="scope">{{ scope.row.login_ip ||'-' }}</template>
        </el-table-column>
        <el-table-column label="已到账金额" align="center">
          <template slot-scope="scope">{{ scope.row.login_ip ||'-' }}</template>
        </el-table-column>
        <el-table-column label="到账详情" align="center">
          <el-button type="text" @click="accountDetails.flag=true">查看</el-button>
        </el-table-column>
        <el-table-column label="状态" align="center">
          <template slot-scope="scope">{{ scope.row.login_ip ||'-' }}</template>
        </el-table-column>
        <el-table-column label="账单详情" align="center">
          <el-button type="text" @click="billingDetails.flag = true">查看</el-button>
        </el-table-column>
      </el-table>
    </template>
    <pagination
      :hidden="page.currentPage<=1"
      :total="page.totalRow"
      :page.sync="page.currentPage"
      :limit.sync="page.pageSize"
      @pagination="onSearch"
    />
    <!-- 到账详情 -->
    <el-dialog title="到账详情" :visible.sync="accountDetails.flag" width="700px">
      <el-table center :data="accountDetails.payArray" border style="width: 100%">
        <el-table-column label="用户支付状态" align="center">
          <template slot-scope="scope">{{ scope.row.id ||'-' }}</template>
        </el-table-column>
        <el-table-column label="偿还方式" align="center">
          <template slot-scope="scope">{{ scope.row.username ||'-' }}</template>
        </el-table-column>
        <el-table-column label="偿还金额" align="center">
          <template slot-scope="scope">{{ scope.row.username ||'-' }}</template>
        </el-table-column>
        <el-table-column label="偿还时间" align="center">
          <template slot-scope="scope">{{ scope.row.status||'-' }}</template>
        </el-table-column>
        <el-table-column label="偿还支付流水号" align="center">
          <template slot-scope="scope">{{ scope.row.login_time ||'-' }}</template>
        </el-table-column>
      </el-table>

      <el-table :data="accountDetails.payStatusArray" border style="width: 100%">
        <el-table-column label="配送信息">
          <el-table-column label="支付方式" align="center">
            <template slot-scope="scope">{{ scope.row.id ||'-' }}</template>
          </el-table-column>
          <el-table-column label="支付时间" align="center">
            <template slot-scope="scope">{{ scope.row.username ||'-' }}</template>
          </el-table-column>
          <el-table-column label="支付流水号" align="center">
            <template slot-scope="scope">{{ scope.row.username ||'-' }}</template>
          </el-table-column>
          <el-table-column label="支付金额" align="center">
            <template slot-scope="scope">{{ scope.row.status||'-' }}</template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 账单详情 -->

    <el-dialog title="账单详情" :visible.sync="billingDetails.flag" width="700px">
      <el-table
        center
        :data="billingDetails.item"
        border
        style="width: 100%"
        :span-method="arraySpanMethod"
      >
        <el-table-column label="项目名称" align="center">
          <template slot-scope="scope">{{ scope.row.name ||'-' }}</template>
        </el-table-column>
        <el-table-column label="规格" align="center">
          <template slot-scope="scope">{{ scope.row.username ||'-' }}</template>
        </el-table-column>
        <el-table-column label="数量" align="center">
          <template slot-scope="scope">{{ scope.row.username ||'-' }}</template>
        </el-table-column>
        <el-table-column label="费用" align="center">
          <template slot-scope="scope">{{ scope.row.status||'-' }}</template>
        </el-table-column>
        <el-table-column label="在院缴费状态" align="center">
          <template slot-scope="scope">{{ scope.row.login_time ||'-' }}</template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 分页
export default {
  name: 'UserPayBilling',
  components: {
    Pagination
  },
  data() {
    return {
      searchKey: {
        medicalInstitution: '', // 医疗机构
        time: '', // 账单日期
        status: '', // 状态
        statusList: [
          { id: '', name: '全部' },
          { id: 1, name: '已平账' },
          { id: 2, name: '待平账' },
          { id: 3, name: '未处理' }
        ],
        compensationWay: '',
        compensationWayList: [
          { id: '', name: '全部' },
          { id: 1, name: '微信' },
          { id: 2, name: '保险理财' }
        ],

        compensationStatus: '',
        compensationStatusList: [
          { id: '', name: '全部' },
          { id: 1, name: '已赔偿' },
          { id: 2, name: '理赔到账' },
          { id: 3, name: '理赔中' }
        ],
        payOrderNo: '', // 账单流水号
        name: '' // 姓名
      },
      searchDate: [{}],

      accountDetails: {
        // 到账详情
        flag: false,
        payArray: [{}],
        payStatusArray: [{}]
      },

      billingDetails: {
        // 账单详情
        flag: false,
        item: [
          {},
          {},
          {
            name:
              '账单总费用：￥       ；医保费用￥      ；自费费用：￥      ；已支付自费费用：￥    ；待支付总费用：￥'
          }
        ]
      },
      page: {
        tableLoading: false,
        currentPage: 1,
        pageSize: 20,
        totalRow: 0,
        totalPage: 0
      }
    }
  },

  created() {},
  methods: {
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      if (this.billingDetails.item.length - 1 === rowIndex) {
        if (columnIndex === 0) {
          return [1, 5]
        } else if (columnIndex === 1) {
          return [0, 0]
        }
      }
    },

    onLoad() {
      this.page.currentPage = 1
      this.onSearch()
    },
    onSearch() {
      //   var params = {}
      //   var that = this
      //   params.pageNumber = that.page.currentPage // 当前页数
      //   params.pageSize = that.page.pageSize // 每页展示条数
      //   if (that.searchKey.time && that.searchKey.time.length > 0) {
      //     params.begin = that.searchKey.time[0]
      //     params.end = that.searchKey.time[1]
      //   } else {
      //     params.begin = ''
      //     params.end = ''
      //   }
      //   params.id = that.searchKey.id
      //   params.name = that.searchKey.name
      //   params.administrator = that.searchKey.administrator
      //   that.page.tableLoading = true
      //   manageRbacUserList(params)
      //     .then(res => {
      //       that.page.tableLoading = false
      //       that.searchDate = res.data
      //     })
      //     .catch(() => {
      //       that.page.tableLoading = true
      //     })
    }
  }
}
</script>

<style scoped>
</style>
